import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { TPetBloodLine } from "../../../Message/Db/Tables/TPetBloodLine";
import { Cache } from "../cache/Cache";
import { EquipmentUtil } from "../view/common/util/EquipmentUtil";
import { PetUtil } from "../view/pet/info/PetUtil";
import { DefInfo } from "./info/DefInfo";
import { HTMLUtil } from "../../../com/gengine/utils/HTMLUtil";
import { GlobalStyle } from "../../common/global/GlobalStyle";
type int = number;
//class PetBloodLineConfig
    
    export  class PetBloodLineConfig
    {
        constructor()
        {
            
            var loc1=ConfigManager.instance.getJSONByFileName("t_pet_blood_line.json");
            this._dic = new Map<any, any> /* flash.utils.Dictionary */();
            this.write(loc1);
            return;
        }

        /* internal  */write(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new TPetBloodLine();
                loc1.configType = loc2.configType;
                loc1.category = loc2.category;
                loc1.type = loc2.type;
                loc1.quality = loc2.quality;
                loc1.name = loc2.name;
                loc1.rate = loc2.rate;
                loc1.num = loc2.num;
                loc1.addAttr = loc2.addAttr;
                loc1.point = loc2.point;
                loc1.icon = loc2.icon;
                loc1.desc = loc2.desc;
                loc1.configNote = loc2.configNote;
                this._dic[loc1.configType + "_" + loc1.category + "_" + loc1.quality + "_" + loc1.type] = loc1;
            }
            return;
        }

        public getItem(arg1: string, arg2: int, arg3: int, arg4: int): TPetBloodLine
        {
            return this._dic[arg1 + "_" + arg2 + "_" + arg3 + "_" + arg4] as TPetBloodLine;
        }

        public getNum(arg1: int, arg2: int, arg3: int): int
        {
            var loc1=0;
            var loc2;
            if (loc2 = this.getItem("BloodUpgradeConfig", arg1, arg2, arg3)) 
            {
                loc1 = loc2.num;
            }
            return loc1;
        }

        public getAttr(arg1: int, arg2: int, arg3: int): string
        {
            var loc1="";
            var loc2;
            if (loc2 = this.getItem("BloodUpgradeConfig", arg1, arg2, arg3)) 
            {
                loc1 = loc2.addAttr;
            }
            return loc1;
        }

        public getAddAttr(arg1: int, arg2: int): string
        {
            var loc1="";
            var loc2;
            if (loc2 = this.getItem("BloodAddConfig", arg1, arg2, 0)) 
            {
                loc1 = loc2.addAttr;
            }
            return loc1;
        }

        public getName(arg1: int): string
        {
            var loc1="";
            var loc2=this.getItem("BloodCategoryConfig", arg1, 0, 0);
            if (loc2) 
            {
                loc1 = loc2.name;
            }
            return loc1;
        }

        public getRealmAndLevel(arg1: int, arg2: Boolean=true): Object
        {
            var loc3=null;
            var loc4=null;
            var loc1={"realm":"", "lv":""};
            var loc2;
            if ((loc2 = this.getItem("BloodCategoryConfig", arg1, 0, 0)) && !(loc2.desc == null) && !(loc2.desc == "")) 
            {
                if ((loc3 = loc2.desc.split("#")).length > 0) 
                {
                    loc4 = loc3[0];
                    if (arg2) 
                    {
                        loc1.realm = loc4;
                    }
                    else 
                    {
                        loc1.realm = loc4.charAt(0);
                    }
                    if (loc3.length > 1) 
                    {
                        loc1.lv = loc3[1];
                    }
                }
            }
            return loc1;
        }

        public getTierName(arg1: int): string
        {
            var loc1="";
            var loc2=this.getItem("BloodQualityConfig", 0, arg1, 0);
            if (loc2) 
            {
                loc1 = loc2.name;
            }
            return loc1;
        }

        public getPositionName(arg1: int, arg2: int): string
        {
            var loc1="";
            var loc2;
            if (loc2 = this.getItem("BloodTypeConfig", arg1, 0, arg2)) 
            {
                loc1 = loc2.name;
            }
            return loc1;
        }

        public getRate(arg1: int, arg2: int, arg3: int): string
        {
            var loc1="";
            var loc2;
            if (loc2 = this.getItem("BloodUpgradeConfig", arg1, arg2, arg3)) 
            {
                loc1 = loc2.rate.toString() + "%";
            }
            return loc1;
        }

        public getItemAttr(arg1: int, arg2: int, arg3: int): string
        {
            var loc4=null;
            var loc5=null;
            var loc1="";
            var loc2=Cache.instance.role.entityInfo.career;
            var loc3;
            if (loc3 = this.getItem("BloodUpgradeConfig", arg1, arg2, arg3)) 
            {
                if (loc5 = (loc4 = EquipmentUtil.getSelfCareerAttribute(loc2, PetUtil.getAttr([loc3.addAttr])))[0] as DefInfo) 
                {
                    loc1 = HTMLUtil.addColor(loc5.name, GlobalStyle.color1) + "    " + HTMLUtil.addColor("+" + loc5.value.toString(), GlobalStyle.color2);
                }
            }
            return loc1;
        }

        public getPonits(arg1: int): Array<any>
        {
            var loc2=null;
            var loc3=null;
            var loc1=[];
            var loc4=0;
            while (loc4 < 7) 
            {
                loc2 = (loc3 = this.getItem("BloodTypeConfig", arg1, 0, loc4 + 1).point).split(",");
                loc1.push(new Object /* flash.geom.Point */(loc2[0], loc2[1]));
                ++loc4;
            }
            return loc1;
        }

        public getTotallAttr(arg1: int, arg2: int, arg3: int): Array<any>
        {
            return this.getCommomTotallAttr(arg1, arg2, arg3).concat(this.getAddTotallAttr(arg1, arg2));
        }

        public getCommomTotallAttr(arg1: int, arg2: int, arg3: int): Array<any>
        {
            var loc3=0;
            var loc4=0;
            var loc1=[];
            var loc2=1;
            while (loc2 <= arg1) 
            {
                loc3 = 1;
                while (loc3 <= 9) 
                {
                    loc4 = 1;
                    while (loc4 <= 7) 
                    {
                        if (loc2 < arg1) 
                        {
                            loc1.push(this.getAttr(loc2, loc3, loc4));
                        }
                        else if (loc3 < arg2) 
                        {
                            loc1.push(this.getAttr(loc2, loc3, loc4));
                        }
                        else if (loc4 <= arg3) 
                        {
                            loc1.push(this.getAttr(loc2, loc3, loc4));
                        }
                        else 
                        {
                            return loc1;
                        }
                        ++loc4;
                    }
                    ++loc3;
                }
                ++loc2;
            }
            return loc1;
        }

        public getAddTotallAttr(arg1: int, arg2: int): Array<any>
        {
            var loc3=0;
            var loc1=[];
            var loc2=1;
            while (loc2 <= arg1) 
            {
                loc3 = 1;
                while (loc3 <= 9) 
                {
                    if (loc2 < arg1) 
                    {
                        loc1.push(this.getAddAttr(loc2, loc3));
                    }
                    else if (loc3 < arg2) 
                    {
                        loc1.push(this.getAddAttr(loc2, loc3));
                    }
                    else 
                    {
                        return loc1;
                    }
                    ++loc3;
                }
                ++loc2;
            }
            return loc1;
        }

        public static get instance(): PetBloodLineConfig
        {
            if (!PetBloodLineConfig._instance) 
            {
                PetBloodLineConfig._instance = new PetBloodLineConfig();
            }
            return PetBloodLineConfig._instance;
        }

        /* internal */ /* var */_dic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: PetBloodLineConfig;
    }
